package com.github.data_manage.dao

import com.github.data_manage.domain.po.Fund
import com.github.data_manage.domain.po.FundInvestments
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query

/**
 *@author CHN
 *@since 2024-08-10 14:48
 */
interface FundInvestmentsDao : BaseDao<FundInvestments> {

    @Query("select f from FundInvestments f where f.modified = false and f.fundId = :fundId order by f.fundId desc")
    fun findAllByFundId(fundId: Int): List<FundInvestments>

    @Query("delete from FundInvestments where fundId = :fundId and id not in (:ids) and modified = false")
    fun deleteAllByFundIdEqualsAndIdNotIn(fundId: Int, ids: Collection<Int>): Int

    fun deleteAllByFundId(fundId: Int)

    @Modifying
    @Query("update FundInvestments set investmentName = :investmentName where investmentId = :investmentId")
    fun updateInvestmentNameByInvestmentId(investmentId: Int,investmentName: String)

    @Query("select f from FundInvestments f where f.modified = false and f.investmentId = :investmentId")
    fun findAllByInvestmentId(investmentId: Int): List<FundInvestments>

    @Query("select f from FundInvestments f where f.investmentId in (:investmentIds)")
    fun findAllByInvestmentIds(investmentId: List<Int>): List<FundInvestments>

    @Modifying
    @Query("update FundInvestments set modified = true where fundId = :fundId")
    fun modifyAllInvestments(fundId: Int)
}
